import { HttpException, HttpStatus, Injectable } from '@nestjs/common';

type GetDataParams = {
  id: string;
  name: string;
};

type AddDataBody = {
  a: string;
  b: string;
  id: string;
};

/**
 *  一般就逻辑放在 service 文件中
 */

@Injectable()
export class TestService {
  getData(params: GetDataParams): string {
    console.log('🚀 ~ AppController ~ getData ~ params:', params)
    if (!params.id || !Number.isInteger(params.id)) {
      throw new HttpException(
        '必须包含参数 id，并且 id 为数字',
        HttpStatus.BAD_REQUEST
      )
    }
    return `get data id value is ${params.id} name value is ${params.name}`
  }

  getAllData(): string {
    return 'get all data';
  }

  addData(body: AddDataBody, query: AddDataBody): string {
    console.log('🚀 ~ AppController ~ addData ~ query:', query)
    console.log('🚀 ~ AppController ~ addData ~ body:', body)
    return `add data body params value is ${JSON.stringify(body)} Query value is ${JSON.stringify(query)}`
  }

  updateData(body: AddDataBody): string {
    return 'update data';
  }

  deleteData(params: GetDataParams): string {
    return 'delete data';
  }
}
